﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TriganleTests.Question;

namespace TriganleTests.Answer
{
    class Edd : Question.ITriangle
    {
        public int InTriangle(MyPoint A, MyPoint B, MyPoint C, MyPoint test)
        {
            try
            {
                //to determine whether can build triangle or not
                //if ((C.Y - A.Y) * (B.X - A.X) != (C.X - A.X) * (B.Y - A.Y)) return -1;


                //(ad＋be＋cf－af－bc－de)/2
                double S = Math.Abs(((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X)));
                if (S == 0) { return -1; }

                //Part A
                MyPoint temp = A;
                A = test;
                double S1 = Math.Abs(((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X)));
                A = temp;

                //Part B
                temp = B;
                B = test;
                double S2 = Math.Abs(((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X)));
                B = temp;

                //Part C
                temp = C;
                C = test;
                double S3 = Math.Abs(((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X)));
                C = temp;

                double newS = S1 + S2 + S3;

                
                return (S == newS) ? 1 : 0;
            }
            catch
            {

            }

            return -1;
        }
    }
}
